//
//  Utils.m
//  Pint
//
//  Created by xiect on 13-10-24.
//  Copyright (c) 2013年 brains. All rights reserved.
//

#import "Utils.h"

@implementation Utils
#define kSOAP_STATUS_ELEMENT @"STATUS"

#define kPREFIX_MESSAGE_FMT @"80%@"
#define kPREFIX_ERROR_FMT   @"90%@"

// アプリを取得
+(BRSAppDelegate*) getAppDelegate{
    return (BRSAppDelegate*)[UIApplication sharedApplication].delegate;
}

// Soap 通信ステータスを取得
// Integer に変更
+(int) getSoapStatusCodeByXmlDoc:(GDataXMLDocument*)xmlDocument{
    GDataXMLElement * rootEl = [xmlDocument rootElement];
    NSString *statusCode = @"0";
    NSString* status = [[[rootEl elementsForName:kSOAP_STATUS_ELEMENT] objectAtIndex:0] stringValue];
    if([status hasPrefix:kPREFIX_ERROR]){
        statusCode = [NSString stringWithFormat:kPREFIX_ERROR_FMT,[status substringFromIndex:1]];
    }else if([status hasPrefix:kPREFIX_MESSAGE]){
        statusCode = [NSString stringWithFormat:kPREFIX_MESSAGE_FMT,[status substringFromIndex:1]];    
    }
    return [statusCode intValue];
}

@end
